﻿Public Class Form1

    ' This SoundPlayer plays a sound whenever the player hits a wall.
    Private appSoundPlayer = New System.Media.SoundPlayer()
    Private MediaDir As String
    Private SoundDir As String

    Public Sub New()

        SoundDir = AppDomain.CurrentDomain.BaseDirectory
        MediaDir = Environment.GetFolderPath(Environment.SpecialFolder.Windows) & "\Media\"

        ' This call is required
        InitializeComponent()

        ' initialization mouse pointer to start
        MoveToStart()

    End Sub

    Private Sub GameSoundPlayer(ByVal strSoundPath As String, ByVal strSoundName As String)
        appSoundPlayer.SoundLocation = strSoundPath & strSoundName
        appSoundPlayer.load()
        appSoundPlayer.play()
    End Sub

    Private Sub finishLabel_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles finishLabel.MouseEnter
        ' Show a congratulatory MessageBox, then close the form.
        GameSoundPlayer(MediaDir, "tada.wav")
        'finishSoundPlayer.play()
        MessageBox.Show("Congratulations!")
        Close()
    End Sub

    ''' <summary>
    ''' Move the pointer to a point 10 pixels down and to the right
    ''' of the starting point in the upper-left corner of the maze.
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub MoveToStart()
        Dim startingPoint As Point
        Dim screenPoint As Point

        startingPoint = Panel1.Location
        startingPoint.Offset(20, 20)
        screenPoint = PointToScreen(startingPoint)
        Cursor.Position = screenPoint
        GameSoundPlayer(SoundDir, "car_start.wav")
        'startSoundPlayer.play()
    End Sub

    Private Sub Panel1_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs)

        ' Show a error MessageBox, if edge of wall, then restart.
        Dim UpperLeftPoint As Point
        Dim BottomRightPoint As Point
        Dim currentPoint As Point
        Dim screenPoint As Point

        screenPoint = Cursor.Position
        UpperLeftPoint = Panel1.Location
        BottomRightPoint = Panel1.Size
        currentPoint = Panel1.PointToClient(screenPoint)

        Dim pointX = currentPoint.X
        Dim pointY = currentPoint.Y
        Stop
        If pointX <= 0 Or pointY <= 0 Then
            GameSoundPlayer(SoundDir, "boo.wav")
            'startSoundPlayer.play()
            MessageBox.Show("Sorry, try again!")

            ' reset mouse pointer to start
            MoveToStart()
        End If

    End Sub

    Private Sub Panel1_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Panel1.MouseEnter

        ' Show a error MessageBox, if edge of wall, then restart.
        Dim currentPoint As Point
        Dim screenPoint As Point

        screenPoint = Cursor.Position
        currentPoint = Panel1.PointToClient(screenPoint)

        Dim pointX = currentPoint.X
        Dim pointY = currentPoint.Y
        If pointX > 50 Or pointY > 50 Then
            GameSoundPlayer(SoundDir, "boo.wav")
            'errorSoundPlayer.play()
            MessageBox.Show("Sorry, try again!")

            ' reset mouse pointer to start
            MoveToStart()
        End If

    End Sub

    Private Sub wall_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label8.MouseEnter, Label9.MouseEnter, Label7.MouseEnter, Label61.MouseEnter, Label60.MouseEnter, Label6.MouseEnter, Label59.MouseEnter, Label57.MouseEnter, Label55.MouseEnter, Label54.MouseEnter, Label53.MouseEnter, Label52.MouseEnter, Label51.MouseEnter, Label50.MouseEnter, Label5.MouseEnter, Label49.MouseEnter, Label48.MouseEnter, Label47.MouseEnter, Label46.MouseEnter, Label45.MouseEnter, Label44.MouseEnter, Label43.MouseEnter, Label42.MouseEnter, Label41.MouseEnter, Label40.MouseEnter, Label4.MouseEnter, Label39.MouseEnter, Label38.MouseEnter, Label37.MouseEnter, Label36.MouseEnter, Label35.MouseEnter, Label34.MouseEnter, Label33.MouseEnter, Label32.MouseEnter, Label31.MouseEnter, Label30.MouseEnter, Label3.MouseEnter, Label29.MouseEnter, Label28.MouseEnter, Label27.MouseEnter, Label26.MouseEnter, Label25.MouseEnter, Label24.MouseEnter, Label23.MouseEnter, Label22.MouseEnter, Label21.MouseEnter, Label20.MouseEnter, Label2.MouseEnter, Label19.MouseEnter, Label18.MouseEnter, Label17.MouseEnter, Label16.MouseEnter, Label15.MouseEnter, Label14.MouseEnter, Label13.MouseEnter, Label12.MouseEnter, Label11.MouseEnter, Label10.MouseEnter, Label1.MouseEnter
        ' When the mouse pointer hits a wall or enters the panel,
        ' call the MoveToStart() method.
        Dim myval As Color
        myval = sender.backcolor
        Select Case myval.Name
            Case "Fuchsia"
                GameSoundPlayer(SoundDir, "boo.wav")
            Case "RoyalBlue"
                GameSoundPlayer(SoundDir, "car_crash.wav")
            Case Else
                GameSoundPlayer(MediaDir, "Windows Critical Stop.wav")
        End Select

        Dim result = MessageBox.Show("Do you want to play again?", "Oops!", MessageBoxButtons.YesNo)
        If (result = DialogResult.No) Then
            Close()
        Else
            MoveToStart()
        End If
    End Sub
End Class
